﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ElectronicJournal
{
    public partial class Editor : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           
            
        }

        protected void UpdatePublications()
        {
            string[] list = System.IO.Directory.GetFiles(Server.MapPath("files"));
            foreach (string str in list)
            {
                LinkButton link = new LinkButton();
                link.Text = str.Substring(str.LastIndexOf("\\") + 1);

                TableRow row = new TableRow();
                TableCell cell = new TableCell();
                cell.Controls.Add(link);
                row.Cells.Add(cell);
                PublicationsTable.Rows.Add(row); 
            }
        }

        protected void ShowPublicationsUploader(object sender, EventArgs e)
        {
            bool tmp = PublicationsListTable.Visible;
            PublicationsUploaderTable.Visible = !PublicationsUploaderTable.Visible;
            PublicationsListTable.Visible = tmp;
        }

        protected void ShowJournalPanel(object sender, EventArgs e)
        {
            JournalPanel.Visible = true;
            PatternPanel.Visible = false;
            PublicationsPanel.Visible = false;
            ReviewersPanel.Visible = false;
        }

        protected void ShowPatternPanel(object sender, EventArgs e)
        {
            JournalPanel.Visible = false;
            PatternPanel.Visible = true;
            PublicationsPanel.Visible = false;
            ReviewersPanel.Visible = false;
        }

        protected void ShowPublicationsPanel(object sender, EventArgs e)
        {
            JournalPanel.Visible = false;
            PatternPanel.Visible = false;
            PublicationsPanel.Visible = true;
            ReviewersPanel.Visible = false;
        }

        protected void UploadPublication(object sender, EventArgs e)
        {
            string str = PublicationsTextBox.Text.Replace(" ", "_") + ".pdf";
            if ((PublicationsUploader.PostedFile != null) && (PublicationsUploader.PostedFile.ContentLength > 0))
            {
                PublicationsUploader.PostedFile.SaveAs(Server.MapPath("files\\publications") + "\\" + System.IO.Path.GetFileName(str));
            }
        }

        protected void ShowPublicationsList(object sender, EventArgs e)
        {
            PublicationsListTable.Visible = !PublicationsListTable.Visible;
            if (PublicationsListTable.Visible) UpdatePublications();
        }

        protected void ShowReviewersPanel(object sender, EventArgs e)
        {
            JournalPanel.Visible = false;
            PatternPanel.Visible = false;
            PublicationsPanel.Visible = false;
            ReviewersPanel.Visible = true;
        }
    }
}